package mfh.liveroam.client;

import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.grid.ColumnConfig;
import com.gwtext.client.widgets.grid.ColumnModel;

public class WidgetFactory {

	public ColumnModel getColumnModel() {

		ColumnConfig[] columns = new ColumnConfig[] {
				// column ID is company which is later used in
				// setAutoExpandColumn
				new ColumnConfig("Album", "album", 60, true, null, "album"),
				new ColumnConfig("GPX", "gpx") };

		ColumnModel columnModel = new ColumnModel(columns);

		return columnModel;
	}

	public String getId() {
		return "picasaAlbums";
	}

	public Store getStore(Object[][] data) {

		RecordDef recordDef = new RecordDef(new FieldDef[] {
				new StringFieldDef("album"), new StringFieldDef("gpx") });

		MemoryProxy proxy = new MemoryProxy(data);

		ArrayReader reader = new ArrayReader(recordDef);
		Store store = new Store(proxy, reader);
		store.load();

		return store;
	}

	public MyGridPanel getGridPanel(Object[][] data) {

		MyGridPanel grid = new MyGridPanel();
		grid.setId(this.getId());

		grid.setStore(this.getStore(data));

		grid.setColumnModel(this.getColumnModel());

		grid.setFrame(true);
		grid.setStripeRows(true);
		grid.setAutoExpandColumn("album");

		grid.setHeight(350);
		grid.setWidth(600);
		grid.setTitle("Picasa Web Albums");

		return grid;

	}

}
